
define('lib/requirejs/css.min!lib/zTree_v3/css/zTreeStyle/zTreeStyle',[],function(){});

/**
 * Created by lizhao on 2016/1/21.
 * update by wangyakun on 2017/5/11
 */
define('simpleTree',[
    'jquery',
    'zTree',
    'lib/requirejs/css.min!lib/zTree_v3/css/zTreeStyle/zTreeStyle.css'
], function ($,zTree) {
    var settings={};
    var tools={
        isArray:function(arr) {
            return Object.prototype.toString.apply(arr) === "[object Array]";
        },
        isObject:function(arr) {
            return Object.prototype.toString.apply(arr) === "[object Object]";
        }
    };
    zTree=(zTree?zTree: $.fn.zTree);
    
    // 处理async 设置
    var asyncTree=function(setting,url,option){
        if(typeof url =='string'){
            setting.async={
                enable: true,
                url:url,
                type:'post',
                autoParam:["id=id","level=level"],
                dataFilter: function(treeId, parentNode, childNodes){
                    return childNodes.beans;
                }
            };
            if(option.async){
                option.async.autoParam&&(setting.async.autoParam=option.async.autoParam);
                option.async.otherParam&&(setting.async.otherParam=option.async.otherParam);
                option.async.type&&(setting.async.type=option.async.type);
                option.async.dataType&&(setting.async.dataType=option.async.dataType);
            }
        }

        return setting;
    };
    
    var objClass = function(obj, setting, zTreeNodes){
        if(obj){
            if(obj instanceof jQuery){
                //存在的jQuery对象的length=1
                if (obj.length>0) {
                    this.$obj = obj;
                }else {
                // 不存在的jQuery对象的length=0
                    alert(obj.selector +'  容器不存在，请重新设置');
                    return ;
                }
            }else if(isDOM(obj)){
                this.$obj = $(obj);
            }else if (typeof(obj) == 'string' && $(obj).length>0) {
                this.$obj = $(obj);
            }
        }else{
            this.$obj = $("<div></div>");            
        }
        this.setting=setting;
        this.init(obj);
        settings=this.setting;
        tools.isArray(zTreeNodes)&&(this.zTreeNodes=zTreeNodes);
        this.tree=zTree.init(this.$obj,this.setting,this.zTreeNodes&&zTreeNodes);
        return this.tree;
    };
    
    $.extend(objClass.prototype,{
            constructor:objClass,
            init:function(obj){
                if(this.$obj.length){
                    this.$obj.addClass("ztree");
                }
            },
            getZTreeObj: function(treeId){
                zTree.getZTreeObj(treeId)
            },
            destroy:function(treeId){
                zTree.destroy(treeId)
            },
            _z:zTree._z,
            
        }
    );
    
    // 重写zTree的_z.tools.clone()方法
    objClass.prototype._z.tools.clone = function (obj) {       
        if (obj === null) return null;
        var o = tools.isArray(obj) ? [] : {};

        var is_data = (tools.isArray(obj) && obj.length);
        var is_filter = (settings.callback && settings.callback.beforeInit);
        for (var i in obj) {
            if (obj[i] instanceof Date) {
                o[i] = new Date(obj[i].getTime())
            } else {
                if (is_data && is_filter) {
                    var filterData = settings.callback.beforeInit(obj[i]);
                    obj[i] = filterData ? filterData : obj[i];
                }
                o[i] = (typeof obj[i] === "object" ? arguments.callee(obj[i]) : obj[i]);
            }
        }
        return o;
    };
    
    var isDOM = function(obj){
        return obj.tagName ?true:false
    } 
     //解决ie下console.log()报错问题
    window.console = window.console || (function(){
        var c = {};
        c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){};
        return c;
    })();
    return {
        zTree: function (obj, setting, zTreeNodes) {
            return new objClass(obj, setting, zTreeNodes)
        },
        checkTree: function (obj, zTreeNodes, option) {
            var setting = {
                check: {
                    enable: true
                }
            };
            if (typeof option == "function") {
                setting.callback ={onCheck:option} ;
            }
            if (tools.isObject(option)) {
                setting = $.extend(setting, option);
                (option.check)&&( setting.check.enable =true,setting.check.chkStyle ='checkbox');
                //兼容之前的写法
                setting.callback||(setting.callback={});
                option.onCheck&&(setting.callback.onCheck=option.onCheck);
                option.beforeInit&&(setting.callback.beforeInit=option.beforeInit);
            }
            setting=asyncTree(setting,zTreeNodes,option);
            return new objClass(obj, setting,zTreeNodes)
        },
        radioTree: function (obj, zTreeNodes, option) {
            var setting = {
                check: {
                    enable: true,
                    chkStyle:"radio"
                }
            };
            if (typeof option == "function") {
                setting.callback ={onCheck:option} ;
            }
            if (tools.isObject(option)) {
                setting = $.extend(setting, option);
                (option.check)&&( setting.check.enable =true,setting.check.chkStyle ='radio');

                //兼容之前的写法
                setting.callback||(setting.callback={});
                option.onCheck&&(setting.callback.onCheck=option.onCheck);
                option.beforeInit&&(setting.callback.beforeInit=option.beforeInit);

            }
            setting=asyncTree(setting,zTreeNodes,option);

            return new objClass(obj, setting, zTreeNodes)
        },
        tierTree: function (obj, zTreeNodes, option) {
            var treeInitData = zTreeNodes;// 保存树初始化的节点数据
            var treeInitSetting = option;// 保存树初始化的配置
            
            var setting = {
                view: {
                    dblClickExpand: false
                },
                check: {
                    enable: false
                },
                callback: {
	                onClick: onClick,
                    onRightClick: onRightClick
	            }
            };
            var funArr1 = []; 
                funArr1.push(setting.callback.onClick);
            //右键弹窗
            var funArr2 = [];
                funArr2.push(setting.callback.onRightClick);
            
            var instance ;   //实例化的对象
            function onClick(e,treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj(obj.attr("id"));
                zTree.expandNode(treeNode, {}, false, false);
                if(funArr1[1]){
                    funArr1[1](e,treeId, treeNode);
                }
			}
            function onRightClick(event, treeId, treeNode) {
                if(funArr2[1]){
                    instance = funArr2[1](event, treeId, treeNode);
                };
                if(instance.clientDefine&&instance.clientDefine.addText){
                    $('.m_add').html(instance.clientDefine.addText);
                }else{
                    $('.m_add').hide();
                };
                if(instance.clientDefine&&instance.clientDefine.removeText){
                    $('.m_del').html(instance.clientDefine.removeText);
                }else{
                    $('.m_del').hide();
                };
                if(instance.clientDefine&&instance.clientDefine.checkText){
                    $('.m_check').html(instance.clientDefine.checkText);
                }else{
                    $('.m_check').hide();
                };
                if(instance.clientDefine&&instance.clientDefine.uncheckText){
                    $('.m_unCheck').html(instance.clientDefine.uncheckText);
                }else{
                    $('.m_unCheck').hide();
                };
                if(instance.clientDefine&&instance.clientDefine.resetText){
                    $('.m_reset').html(instance.clientDefine.resetText);
                }else{
                    $('.m_reset').hide();
                };
                if(event.target.nodeName != "UL"){
                    var boxTarget = $(event.target).parents('.ztree')[0];
                    var left =  event.clientX - boxTarget.getBoundingClientRect().left; 
                    var top =  event.clientY - boxTarget.getBoundingClientRect().top; 
                    var boxscrollTop = $('.sn-simpletree-rmenu').scrollTop();
                    var boxscrollLeft = $('.sn-simpletree-rmenu').scrollLeft();
                    if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
                        // zTree.cancelSelectedNode(); //取消节点的选中状态,如果省略此参数，则将取消全部被选中节点的选中状态。
                        // showRMenu("root", left, top);
                    } else if (treeNode && !treeNode.noR) {
                        instance.instanceObj.selectNode(treeNode,false,true); // 选中指定节点
                        showRMenu("node", left + boxscrollLeft,  top + boxscrollTop);
                    }
                    
                }
                
            }
            function showRMenu(type, x, y) {
                    $(".rmenu ul").show();
                    if (type=="root") {
                        $(".m_del").hide();
                        $(".m_check").hide();
                        $(".m_unCheck").hide();
                        $(".m_reset").hide();
                    } 
                    $(".rmenu").css({"top":y+"px", "left":x+"px", "display":"block"});
                    $("body").bind("mousedown", onBodyMouseDown);
            }
            function hideRMenu() {
                if ($(".rmenu")) $(".rmenu").css({"display":"none"});
                $("body").unbind("mousedown", onBodyMouseDown);
            }
            function onBodyMouseDown(event){
                if (!($(event.target).attr('class') == "rmenu" || $(event.target).parents(".rmenu").length>0)) {
                    $(".rmenu").css({"display":"none"});
                }
            }
            
            function addTreeNode() {
                hideRMenu();
                var newNode;
                if(instance.clientDefine&&instance.clientDefine.newNodes){
                    if(typeof instance.clientDefine.newNodes == "object"){
                        newNode = instance.clientDefine.newNodes;
                        addInit();
                    }
                    if(typeof instance.clientDefine.newNodes == "string"){
                        $.ajax({
                            url: instance.clientDefine.newNodes,
                            type: 'post',
                            dataType: "json",
                            async: true,
                            success:function(data){
                                newNode = data.beans;
                                addInit();
                            }   
                        });
                    }
                    
                }
                function addInit(){                   
                    if (instance.instanceObj.getSelectedNodes()[0]) {  //获取 zTree 当前被选中的节点数据集合
                        for(var i=0, len = newNode.length; i<len; i++){
                            newNode[i].checked = instance.instanceObj.getSelectedNodes()[0].checked;
                        }
                        instance.instanceObj.addNodes(instance.instanceObj.getSelectedNodes()[0], newNode);
                    } else {
                        instance.instanceObj.addNodes(null, newNode);
                    }
                    if(instance.clientDefine&&(typeof (instance.clientDefine.addCallback) == 'function')){
                        instance.clientDefine.addCallback();
                    }   
                }
                
            }
            function removeTreeNode() {
                hideRMenu();
                var nodes = instance.instanceObj.getSelectedNodes();
                if (nodes && nodes.length>0) {
                    if (nodes[0].children && nodes[0].children.length > 0) {
                        var msg = "要删除的节点是父节点，如果删除将连同子节点一起删掉。\n\n请确认！";
                        if (confirm(msg)==true){
                            instance.instanceObj.removeNode(nodes[0]);
                        }
                    } else {
                        instance.instanceObj.removeNode(nodes[0]);
                    }
                }
                if(instance.clientDefine&&(typeof (instance.clientDefine.removeCallback) == 'function')){
                    instance.clientDefine.removeCallback();
                }
            }
            function checkTreeNode(checked) {
                var nodes = instance.instanceObj.getSelectedNodes();
                if (nodes && nodes.length>0) {
                    instance.instanceObj.checkNode(nodes[0], checked, true); //勾选 或 取消勾选 单个节点。[setting.check.enable = true 时有效]
                }
                hideRMenu();
                if(instance.clientDefine&&(typeof (instance.clientDefine.checkCallback) == 'function')&& checked){
                    instance.clientDefine.checkCallback();
                }
                if(instance.clientDefine&&(typeof (instance.clientDefine.uncheckCallback) == 'function')&& (!checked)){
                    instance.clientDefine.uncheckCallback();
                }
            }
            function resetTree() {
                hideRMenu();
                
                $.fn.zTree.init(obj, treeInitSetting , treeInitData);
                var resetTimer =setTimeout(function(){
                    obj.append('<li class="rmenu"><ul><li class="m_add"></li><li class="m_del"></li><li class="m_check"></li><li class="m_unCheck"></li><li class="m_reset"></li></ul></li>');    
                    $('.m_add').click(function(){
                        addTreeNode();
                    });
                    $('.m_del').click(function(){
                            removeTreeNode();
                    });
                    $('.m_check').click(function(){
                            checkTreeNode(true);
                    });
                    $('.m_unCheck').click(function(){
                            checkTreeNode(false);
                    });
                    $('.m_reset').click(function(){
                            resetTree();
                    });
                    resetTimer = null;
                },100);
                if(instance.clientDefine&&(typeof (instance.clientDefine.resetCallback) == 'function')){
                    instance.clientDefine.resetCallback();
                }
            }

            if (typeof option == "function") {
                setting.callback ={onClick:option} ;
            }
            if (tools.isObject(option)) {
                setting = $.extend(setting, option);

                //兼容之前的写法
                setting.callback||(setting.callback={});
                if(option.callback&&option.callback.onClick){
                    funArr1.push(option.callback.onClick); 
                	setting.callback.onClick= funArr1[0];
                }else{
                	setting.callback.onClick=onClick;
                }
                //右键弹窗功能
                if(option.callback&&option.callback.onRightClick){
                    funArr2.push(option.callback.onRightClick);
                    setting.callback.onRightClick = funArr2[0];
                    obj.addClass('sn-simpletree-rmenu');
                        var timer =setTimeout(function(){
                            obj.append('<li class="rmenu"><ul><li class="m_add"></li><li class="m_del"></li><li class="m_check"></li><li class="m_unCheck"></li><li class="m_reset"></li></ul></li>');    
                            $('.m_add').click(function(){
                                addTreeNode();
                            });
                            $('.m_del').click(function(){
                                    removeTreeNode();
                            });
                            $('.m_check').click(function(){
                                    checkTreeNode(true);
                            });
                            $('.m_unCheck').click(function(){
                                    checkTreeNode(false);
                            });
                            $('.m_reset').click(function(){
                                    resetTree();
                            });
                            timer = null;
                        },100);
                        
                }else{
                    setting.callback.onRightClick = null;
                }

                option.beforeInit&&(setting.callback.beforeInit=option.beforeInit);
            }
            setting=asyncTree(setting,zTreeNodes,option);
            
            return new objClass(obj, setting, zTreeNodes);
        }
    };

});


(function(c){var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));})
('/*-------------------------------------\r\nzTree Style\r\n\r\nversion:\t3.5.19\r\nauthor:\t\tHunter.z\r\nemail:\t\thunter.z@263.net\r\nwebsite:\thttp://code.google.com/p/jquerytree/\r\n\r\n\r\n修改记录：\r\n\r\n根据中移在线UI规范对ztree样式进行了修改 20170111\r\n\r\n-------------------------------------*/\r\n\r\n.ztree * {padding:0; margin:0; font-size:12px;}\r\n.ztree {margin:0; padding:5px; color:#333;}\r\n.ztree li{padding:0; margin:0; list-style:none; line-height:22px; text-align:left; white-space:nowrap; outline:0;}\r\n.ztree li ul{ margin:0; padding:0 0 0 18px;}\r\n.ztree li ul.line{ /*UI规范不再显示竖向虚线*/}\r\n\r\n.ztree li a {padding:0 3px 0 0; margin:0; margin-top: 2px; cursor:pointer; height:17px; color:#333; background-color: transparent;\r\n\ttext-decoration:none; vertical-align:top; display: inline-block;}\r\n.ztree li a:hover {text-decoration:underline;}\r\n.ztree li a.curSelectedNode {padding-top:0px; background-color:#c4e4f5; color:black; height:19px; }\r\n.ztree li a.curSelectedNode_Edit {padding-top:0px; background-color:#c4e4f5; color:black; height:16px; }\r\n.ztree li a.tmpTargetNode_inner {padding-top:0px; background-color:#c4e4f5; color:white; height:16px; }\r\n.ztree li a.tmpTargetNode_prev {}\r\n.ztree li a.tmpTargetNode_next {}\r\n.ztree li a input.rename {height:14px; width:80px; padding:0; margin:0;\r\n\tfont-size:12px; border:1px #7EC4CC solid; *border:0px}\r\n.ztree li span {line-height:16px; margin-right:2px}\r\n.ztree li span.button {line-height:0; margin:0; width:16px; height:16px; display: inline-block; vertical-align:middle;\r\n\tborder:0 none; cursor: pointer;outline:none;\r\n\tbackground-color:transparent; background-repeat:no-repeat; background-attachment: scroll;\r\n\tbackground-image:url(\'\'); *background-image:url(\"../../../src/lib/zTree_v3/css/zTreeStyle/img/zTreeStandard.gif\")}\r\n\r\n.ztree li span.button.chk {width:16px; height:16px; margin:0 5px 0 0; cursor: auto;}\r\n.ztree li span.button.chk.checkbox_false_full {background-position:0 0;}\r\n.ztree li span.button.chk.checkbox_false_full_focus {background-position:0 -17px;}\r\n.ztree li span.button.chk.checkbox_false_part {background-position:0 0;}\r\n.ztree li span.button.chk.checkbox_false_part_focus {background-position:0 -17px;}\r\n.ztree li span.button.chk.checkbox_false_disable {background-position:0 -34px;}\r\n.ztree li span.button.chk.checkbox_true_full {background-position:-17px 0;}\r\n.ztree li span.button.chk.checkbox_true_full_focus {background-position:-17px 0;}\r\n.ztree li span.button.chk.checkbox_true_part {background-position:-17px 0;}\r\n.ztree li span.button.chk.checkbox_true_part_focus {background-position:-17px 0;}\r\n.ztree li span.button.chk.checkbox_true_disable {background-position:-17px -17px;}\r\n\r\n.ztree li span.button.chk.radio_false_full {background-position:-34px 0;}\r\n.ztree li span.button.chk.radio_false_full_focus {background-position:-34px -17px;}\r\n.ztree li span.button.chk.radio_false_part {background-position:-34px 0;}\r\n.ztree li span.button.chk.radio_false_part_focus {background-position:-34px -17px;}\r\n.ztree li span.button.chk.radio_false_disable {background-position:-34px -34px;}\r\n.ztree li span.button.chk.radio_true_full {background-position:-51px 0;}\r\n.ztree li span.button.chk.radio_true_full_focus {background-position:-51px 0;}\r\n.ztree li span.button.chk.radio_true_part {background-position:-51px 0;}\r\n.ztree li span.button.chk.radio_true_part_focus {background-position:-51px 0;}\r\n.ztree li span.button.chk.radio_true_disable {background-position:-51px -17px;}\r\n\r\n.ztree li span.button.switch {width:18px; height:18px;}\r\n.ztree li span.button.root_open{background-position:-68px -16px;}\r\n.ztree li span.button.root_close{background-position:-68px 1px;}\r\n.ztree li span.button.roots_open{background-position:-68px -16px;}\r\n.ztree li span.button.roots_close{background-position:-68px 1px;}\r\n.ztree li span.button.center_open{background-position:-68px -16px;}\r\n.ztree li span.button.center_close{background-position:-68px 1px;}\r\n.ztree li span.button.bottom_open{background-position:-68px -16px;}\r\n.ztree li span.button.bottom_close{background-position:-68px 1px;}\r\n.ztree li span.button.noline_open{background-position:-68px -16px;}\r\n.ztree li span.button.noline_close{background-position:-68px 1px;}\r\n.ztree li span.button.root_docu{ background:none; margin-right: 3px;}\r\n.ztree li span.button.roots_docu{background:none;}\r\n.ztree li span.button.center_docu{background: none;}\r\n.ztree li span.button.bottom_docu{background-position:-56px -36px;}\r\n.ztree li span.button.noline_docu{ background:none; margin-right: 3px;}\r\n\r\n.ztree li span.button.ico_open{margin-right:5px; background-position:-99px 1px; vertical-align:top; *vertical-align:middle}\r\n.ztree li span.button.ico_close{margin-right:5px; background-position:-99px 1px; vertical-align:top; *vertical-align:middle}\r\n.ztree li span.button.ico_docu{margin-right:5px; background-position:-99px -16px; vertical-align:top; *vertical-align:middle}\r\n.ztree li span.button.edit {}\r\n.ztree li span.button.remove {}\r\n\r\n.ztree li span.button.ico_loading{margin-right:5px; background:url(\'\') no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}\r\n\r\nul.tmpTargetzTree {background-color:#FFE6B0; opacity:0.8; filter:alpha(opacity=80)}\r\n\r\nspan.tmpzTreeMove_arrow {width:16px; height:16px; display: inline-block; padding:0; margin:2px 0 0 1px; border:0 none; position:absolute;\r\n\tbackground-color:transparent; background-repeat:no-repeat; background-attachment: scroll;\r\n\tbackground-position:-110px -80px; background-image:url(\'\'); *background-image:url(\"../../../src/lib/zTree_v3/css/zTreeStyle/img/zTreeStandard.gif\")}\r\n\r\nul.ztree.zTreeDragUL {margin:0; padding:0; position:absolute; width:auto; height:auto;overflow:hidden; background-color:#cfcfcf; border:1px #00B83F dotted; opacity:0.8; filter:alpha(opacity=80)}\r\n.zTreeMask {z-index:10000; background-color:#cfcfcf; opacity:0.0; filter:alpha(opacity=0); position:absolute}\r\n\r\n/* level style*/\r\n/*.ztree li span.button.level0 {\r\n\tdisplay:none;\r\n}\r\n.ztree li ul.level0 {\r\n\tpadding:0;\r\n\tbackground:none;\r\n}*/');
